<?php

namespace App\Http\Resources\Front;

use Illuminate\Http\Resources\Json\Resource;

class Order extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'order_no' => $this->order_no,
            'status' => $this->status,
            'status_label' => $this->status_label,
            'order_amount' => $this->order_amount_total,
            'address' => $this->area . $this->address,
            'contact_tel' => $this->contact_tel,
            'contact_name' => $this->contact_name,
            'buyer_message' => $this->buyer_message,
            'created_at' => $this->created_at->format('Y-m-d H:m:s'),
            'friend_date' => friendDate($this->created_at->getTimestamp()),
            'order_items' => OrderProduct::collection($this->whenLoaded('orderItems')),
            'user' => $this->whenLoaded('user'),
            'shop' => $this->whenLoaded('shop')
        ];
    }
}
